#ifndef _SERIAL_PORT_DATA_H
#define _SERIAL_PORT_DATA_H

#include "serial_utility.h"

#define RECV_BUFFER_SIZE (1024)
#define RECV_BUFFER_WATERMARK_SIZE (30)

#define MAX_PACK_LEN	(1500)
#define UART_PACK_MIN_LEN (7)
#define UART_DATA_HEAD (0xAA)
#define UART_DATA_TAIL (0x55)
#define UART_DATA_TRANSLATE (0xCC)

typedef struct _server_cmd_t{
        U8 addr[6];
		U32 index;
		U8 type;
		U8 *pdata;
		U16 length;
		
}server_cmd_t;

typedef struct tagComStream
{
	U8* pBuffer;		
	U16 nLenOfBuf;		
}ComStream_t;

typedef struct tagPack
{
	U8 cmdID;				//
	U8 option;				//
	U8* pData;				//
	U16 nLenOfData;			//
}Pack_t;

//解包数据结构
typedef struct tagUnpack
{
	U8 cmdID;				//命令id，输出参数
	U8 option;				//选项
	U16 indexOfHead;		//包头索引
	U16 indexOfTail;		//包尾索引
	U8* pData;			//缓冲区数据
	U16 lenOfData;	//缓冲区数据长度
}UnPack_t;

typedef enum tagEnumPTL_STATUS
{
	PTL_NO_ERROR = 0,		//解包正确
	PTL_CHECKSUM_ERROR,	    //校验错误
	PTL_LENGTH_ERROR,		//包长度错误
	PTL_HEAD_ERROR,			//包头错误
	PTL_TAIL_ERROR,			//包尾错误
	PTL_DATA_ERROR			//数据域错误
}PTL_STATUS;

U16 uart_base_wrap(U8 *wrap_buffer, server_cmd_t *server_cmd);
PTL_STATUS uart_unpack(const ComStream_t * inStream,UnPack_t *pResult);			
PTL_STATUS uart_pack(const Pack_t*  pPack, ComStream_t* outStream);	




#endif  // _SERIAL_PORT_DATA_H